package edu.uj.petri.view;

import edu.uj.petri.document.Document;
import edu.uj.petri.model.InhibitorArc;
import java.awt.Color;
import java.awt.geom.Rectangle2D;
import java.util.ListIterator;

public class InhibitorArcView extends ArcView {
    
    private InhibitorArc arc;
    
    public InhibitorArcView( NodeView begin) {
        super(begin);
    }

    public void draw(Canvas canvas) {
        
        if (begin == null) return;
        
        if (floatingEnd == null)
        {       

            for (ArcSegment s : segments)
                if (s.getNodeBegin() != null) s.drawCircle(canvas);
                else s.draw(canvas);
            
        
           if (selected) for (LinkingPoint p: linkingPoints) p.draw( canvas );         
        }
        else 
        {
            ArcSegment.drawLineWithCircle( begin.position.getX(), begin.position.getY(), floatingEnd.getX(), floatingEnd.getY(), canvas, Color.BLACK);
        }
    }

    /**
     * returns false if such element cannot be end of arc (eg. method is called 
     *    with a place and the arc already begins in a place).
     */
    public boolean canBeEnd(NodeView node) {
        return !(node instanceof PlaceView);
    }

    /**
     * this method is called when Observed wants to notify all its Observers of 
     *    change in its state.
     * @param eventCode type of event that caused the notification. Observed classes 
     *    should define their unique codes as public final static fields.
     */
    public void notifyFromObserved(int eventCode) {
        // does nothing
    }

    protected void finishCreating() {
        arc = Document.getActiveDocument().getModel().createInhibitorArc(begin.getNode(), end.getNode());
        arc.subscribe(this);
    }

    public boolean crossesRectangle(Rectangle2D rect) {
        
        // TODO
        return false;
    }
    
    private static final long serialVersionUID = -3370410699729831704L;
}
